package com.liy.cloud.auth.client.job;

import com.liy.cloud.auth.client.config.UserAuthConfig;
import com.liy.cloud.auth.client.feign.AuthorizationFeignClient;
import com.liy.framework.common.extvo.ResultVO;
import com.liy.framework.common.token.Base64Utils;
import com.liy.framework.common.utils.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class AuthConfigJob {

    private static Logger log = LoggerFactory.getLogger(AuthConfigJob.class);

    @Autowired
    private UserAuthConfig keyConfig;

    @Autowired
    private AuthorizationFeignClient authorizationFeignClient;

    @Scheduled( fixedRate = 300000L )
    public void generateStationTicketDailyReport() {
        log.info("auto syn authentication: " + DateUtil.getTimeNow());

        try {
            ResultVO resultVO = this.authorizationFeignClient.getUserPublicKey(this.keyConfig.getClientId(), this.keyConfig.getClientSecret());
            log.warn("syn authentication status: " + resultVO.getMessage());
            if (resultVO.isSuccess() && resultVO.getData() != null) {
                this.keyConfig.setPubKeyByte(Base64Utils.decode(resultVO.getData().toString()));
            }
        } catch (Exception var2) {
            log.error("syn authentication key error: " + var2.getMessage(), var2);
        }

    }
}
